package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.netEase.dao.shopggDao;
import org.netEase.entity.goodsType;
import org.netEase.entity.shopgg;
import org.netEase.entity.typegg;
import org.netEase.util.BaseDao;

public class shopggImpl extends BaseDao implements shopggDao {

	@Override
	public int add(shopgg so) {
		 String sql="INSERT  INTO shopgg(Sid,tgId,spgValues,spgValues2)VALUES(?,?,?,?)";
		   return super.executeUpdate(sql, so.getSid(),so.getTgId(),so.getSpgValues(),so.getSpgValues2());
	}

	@Override
	public int update(shopgg so) {
		String sql = "update shopgg set tgId = ?,spgValues=?,spgValues2=? where sid = ?";
		return super.executeNoQuery(sql,so.getTgId(),so.getSpgValues(),so.getSpgValues2(),so.getSid());
	}

	@Override
	public goodsType getsid(int sid) {
		String sql="SELECT * FROM shopgg s INNER JOIN typegg t ON s.tgid=t.tgid WHERE s.sid = ?";
		ResultSet rs = super.executeQuery(sql,sid);
		goodsType shopgg =null;
		try {
			while(rs.next()) {
				shopgg = new goodsType();
				shopgg.setSid(rs.getInt("sid"));
				shopgg.setSpgid(rs.getInt("spgid"));
				typegg typegg = new typegg();
				typegg.setTgname(rs.getString("tgname"));
				typegg.setZid(rs.getInt("zid"));
				typegg.setTgid(rs.getInt("tgid"));
				shopgg.setTypegg(typegg);
				shopgg.setSpgvalues(rs.getString("spgvalues"));
				shopgg.setSpgvalues2(rs.getString("spgvalues2"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return shopgg;
	
	}
	/*public static void main(String[] args) {
		shopggDao shopdao = new shopggImpl();
		goodsType shopgg =shopdao.getsid(84);
		System.out.println(shopgg.getSpgvalues2());
	}*/

}
